package com.imddysc.spbbatchitemreadererrorrestart;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemStreamReader;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.file.FlatFileItemReader;
import org.springframework.batch.item.file.FlatFileItemWriter;
import org.springframework.batch.item.file.mapping.DefaultLineMapper;
import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer;
import org.springframework.batch.item.file.transform.FieldSet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.validation.BindException;

@Configuration
@EnableBatchProcessing
public class ErrorRestartItemStreamReaderDemo {
	
	@Autowired
	private JobBuilderFactory jobBuilderFactory;
	
	@Autowired
	private StepBuilderFactory stepBuilderFactory;
	
	
	@Autowired
	@Qualifier("errorRestartItemWriter")
	private ItemWriter<Customer> errorRestartItemWriter;

	@Autowired
	@Qualifier("errorRestartItemStreamReader")
	private ErrorRestartItemStreamReader errorRestartItemStreamReader;
	
	@Bean
	public Job errorRestartItemStreamReaderDemoJob() {
		return jobBuilderFactory.get("errorRestartItemStreamReaderDemoJob")
				.start(errorRestartItemStreamReaderDemoStep())
				.build();
	}

	@Bean
	public Step errorRestartItemStreamReaderDemoStep() {
		return stepBuilderFactory.get("errorRestartItemStreamReaderDemoStep")
				.<Customer,Customer>chunk(5)
				.reader(errorRestartItemStreamReader)
				.writer(errorRestartItemWriter)
				.build();
	}

	
}
